package com.lfy.yunpicture.model.enums;
import lombok.Getter;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 空间级别
 */
@Getter
public enum SpaceLeaveEnum {

    COMMON("普通版", 0, 100L * 1024 * 1024, 100),
    VIP("VIP版", 1, 1000L * 1024 * 1024, 1000),
    SUPER_VIP("旗舰版", 2, 10000L * 1024 * 1024, 10000);

    private final String spaceName;
    private final Integer spaceLeave;
    private final long maxSize;
    private final long maxCount;

    SpaceLeaveEnum(String spaceName, int spaceLeave, long maxSize, long maxCount) {
        this.spaceName = spaceName;
        this.spaceLeave = spaceLeave;
        this.maxSize = maxSize;
        this.maxCount = maxCount;
    }

    /**
     * 获取值列表
     *
     * @return
     */
    public static List<Integer> getSpaceLeaveValues() {
        return Arrays.stream(values()).map(SpaceLeaveEnum::getSpaceLeave).collect(Collectors.toList());
    }

    /**
     * 根据 spaceLeave 获取枚举
     *
     * @param spaceLeave
     * @return
     */
    public static SpaceLeaveEnum getEnumBySpaceLeave(Integer spaceLeave) {
        if (spaceLeave == null) {
            return null;
        }
        for (SpaceLeaveEnum anEnum : SpaceLeaveEnum.values()) {
            if (anEnum.spaceLeave.equals(spaceLeave)) {
                return anEnum;
            }
        }
        return null;
    }
}